@()(implicit session: Session)
@account.main("账号管理") {


    <div class="page-bar">
        <ul class="page-breadcrumb">
            <li>
                <b style="font-size: 20px;">账号</b>
            </li>
            <li style="margin-left: 2em;">
                <a href="routes.AccountController.accountBefore()" ><i class="fa fa-cloud-upload"></i>
                    新增账号</a>
            </li>

            <li style="margin-left: 2em;">
                <a href="routes.AccountController.manageBefore()"><i class="fa fa-sliders"></i>
                    账号管理</a>
            </li>
        </ul>
    </div>

    <div class="row-fluid">

        <div class="row">

            <div class="col-md-12 col-sm-12">
                <div class="portlet blue-soft box">

                    <div class="portlet-title">
                        <div class="caption">
                            新增账号
                        </div>
                    </div>

                    <div class="portlet-body">


                        <form class="registration-form form-horizontal" id="UploadForm" accept-charset="UTF-8">

                            <div class="form-group">
                                <label class="col-sm-12">账号:</label>
                                <div class="col-sm-4 indent">
                                    <input type="text" class="form-control" name="account" >
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-12">指导老师:</label>
                                <div class="col-sm-4 indent">
                                    <input type="text" class="form-control" name="name" >
                                </div>
                            </div>


                            <div class="form-group">
                                <label class="col-sm-12">密码:</label>
                                <div class="col-sm-4 indent">
                                    <input type="text" class="form-control" name="password" >
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-12">再次输入密码:</label>
                                <div class="col-sm-4 indent">
                                    <input type="text" class="form-control" name="password2" >
                                </div>
                            </div>


                            <div class="form-group">
                                <div class = "actions indent col-sm-4">
                                    <button type="button" class="btn btn-primary" style="width: 100%;" id="search" onclick="Create()">
                                        新增</button>
                                </div>
                            </div>

                        </form>

                    </div>
                </div>
            </div>
        </div>
    </div>



    <script>


            $(function () {

                formValidation();
            });

            function formValidation() {
                $('#UploadForm').formValidation({
                    framework: 'bootstrap',
                    icon: {
                        valid: 'glyphicon glyphicon-ok',
                        invalid: 'glyphicon glyphicon-remove',
                        validating: 'glyphicon glyphicon-refresh'
                    },
                    fields: {
                        account: {
                            validators: {
                                notEmpty: {
                                    message: '账号不能为空！'
                                },
                                remote: {
                                    url: 'routes.AccountController.checkAccount()',
                                    type: "GET",
                                    message: '账号已存在！',
                                    delay: 1000
                                }
                            }
                        },
                        name: {
                            validators: {
                                notEmpty: {
                                    message: "姓名不能为空！"
                                },
                                remote: {
                                    url: '@routes.AccountController.checkName()',
                                    type: "GET",
                                    message: "姓名已存在！",
                                    delay: 1000
                                }
                            }
                        },
                        password: {
                            validators: {
                                notEmpty: {
                                    message: "密码不能为空！"
                                }
                            }
                        },
                        password2: {
                            validators:{
                                notEmpty: {
                                    message: "不能为空！"
                                },
                                identical: {
                                    field: 'password',
                                    message: '与之前输入的密码不一致!'
                                }
                            }
                        }
                    }
                })
            }

            function Create() {
                var form = $("#UploadForm");
                var fv = form.data("formValidation");
                fv.validate();
                if (fv.isValid()) {
                    var index = layer.load(1);
                    $.ajax({
                        url: "@routes.AccountController.addAccount()",
                        type: "post",
                        data: $("#UploadForm").serialize(),
                        success: function () {
                            layer.close(index);
                            swal({
                                        title: "\n",
                                        text: "新增账号成功",
                                        type: "success"}
                            )
                        }
                    })
                }
            }


    </script>


}